//! 集合工具
//! 
//! 提供集合操作的工具函数

use std::collections::{HashMap, HashSet};

/// 合并两个HashMap
pub fn merge_hashmaps<K, V>(map1: HashMap<K, V>, map2: HashMap<K, V>) -> HashMap<K, V> 
where 
    K: Eq + std::hash::Hash,
{
    let mut result = map1;
    for (k, v) in map2 {
        result.insert(k, v);
    }
    result
}

/// 求两个集合的交集
pub fn intersect_sets<T>(set1: &HashSet<T>, set2: &HashSet<T>) -> HashSet<T>
where
    T: Clone + Eq + std::hash::Hash,
{
    set1.intersection(set2).cloned().collect()
}

/// 求两个集合的并集
pub fn union_sets<T>(set1: &HashSet<T>, set2: &HashSet<T>) -> HashSet<T>
where
    T: Clone + Eq + std::hash::Hash,
{
    set1.union(set2).cloned().collect()
}